<?php
	/*!
	 * \brief Configures theme after setup.
	 */
	function awisp_after_theme_setup(){
		add_theme_support("post-thumbnails");
	}
	add_action("after_setup_theme", "awisp_after_theme_setup");
	/*!
	 * \brief Configures theme before setup.
	 */
	function awisp_before_theme_setup(){
		load_theme_textdomain("awisp.theme", get_template_directory() . "/languages");
	}
	add_action("init", "awisp_before_theme_setup");
	/*!
	 * \brief Creates navigation links for posts.
	 * \param prev Previous link.
	 * \param next Next link.
	 * \returns navigation links for posts.
	 */
	function awisp_posts_nav_links($prev, $next){
		if(!$prev && !$next){
			return null;
		}
		$output = '<div class="posts-nav">';
		if($prev){
			$output .= '<div class="nav-previous">' . $prev . '</div>';
		}
		if($next){
			$output .= '<div class="nav-next">' . $next . '</div>';
		}
		$output .= '</div>';
		return $output;
	}
	/*!
	 * \brief Sets robots.txt file.
	 * \returns robots.txt file content.
	 */
	function awisp_robots_access(){
		header("Content-Type: text/plain; charset=utf-8");
		$output = "User-agent: *" . PHP_EOL;
		$public = get_option("blog_public");
		if($public == "0"){
			$output .= "Disallow: /" . PHP_EOL;
		}
		else{
			$site_url = parse_url(site_url());
			$path = (!empty($site_url["path"])) ? $site_url["path"]: null;
			$output .= "Disallow: " . $path . "/wp-admin/" . PHP_EOL;
			$output .= "Disallow: " . $path . "/wp-includes/" . PHP_EOL;
		}
		return $output;
	}
	add_filter("robots_txt", "awisp_robots_access");
	/*!
	 * \brief Sets search query for posts only.
	 * \param query The search query.
	 * \returns modified search query.
	 */
	function awisp_search_posts_only($query){
		if($query->is_search == true){
			$query->set("post_type", "post");
		}
		return $query;
	}
	add_filter("pre_get_posts", "awisp_search_posts_only");
?>